#include <iostream>
#include <list>
#include <deque>
#include <algorithm>
#include "countptr.h"
using namespace std;

void printCountedPtr (CountedPtr<int> elem)
{
	cout<<*elem<<' ';
}

int countptrex()
{
	static int values[] = {3, 5, 9, 1, 6, 4};

	typedef CountedPtr<int> IntPtr;
	deque<IntPtr> coll1;
	list<IntPtr> coll2;

	for(int i=0; i<sizeof(values)/sizeof(values[0]); ++i){
		IntPtr ptr(new int(values[i]));
		coll1.push_back(ptr);
        coll2.push_front(ptr);
    }

    for_each(coll1.begin(), coll1.end(),
        printCountedPtr);
    cout<<endl;

    for_each(coll2.begin(), coll2.end(),
        printCountedPtr);
    cout<<endl;

    cout<<endl;

    *coll1[2] *= *coll1[2];

    (**coll1.begin()) *= -1;
    (**coll2.begin()) = 0;

    for_each(coll1.begin(), coll1.end(),
        printCountedPtr);
    cout<<endl;

    for_each(coll2.begin(), coll2.end(),
        printCountedPtr);
    cout<<endl;
    
    return 0;
}